package cn.MaySoon.shenfu;

import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.serverct.ersha.api.AttributeAPI;
import org.serverct.ersha.attribute.data.AttributeData;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class jinengap {
        public static void updateAttribute(Player p){
            File file = new File(main.plugin.getDataFolder() + "/PlayerData/" + p.getName() + ".yml");
            YamlConfiguration data = YamlConfiguration.loadConfiguration(file);
            int 攻击level = data.getInt("jineng.攻击");
            int 防御level = data.getInt("jineng.防御");
            int 生命level = data.getInt("jineng.生命");
            int 高级生命level = data.getInt("jineng.高级生命");
            int 大师level = data.getInt("jineng.大师");

            int 物理伤害 = 0;
            if (攻击level!=0){
                int 攻击attr = main.config.getInt("jineng.攻击."+攻击level+".attr");

                if (大师level!=0){
                int 大师attr = main.config.getInt("jineng.大师."+大师level+".attr");
                double 大师percent = (double) 大师attr/100;
                攻击attr = 攻击attr+(int) (攻击attr*大师percent);
                }
                物理伤害 = 物理伤害+攻击attr;
            }

            int 物理防御 =0;
            if (防御level!=0){
                int 防御attr = main.config.getInt("jineng.防御."+防御level+".attr");

                if (大师level!=0){
                    int 大师attr = main.config.getInt("jineng.大师."+大师level+".attr");
                    double 大师percent = (double) 大师attr/100;
                    防御attr = 防御attr+(int) (防御attr*大师percent);
                }
                物理防御 = 物理防御+防御attr;
            }

            int 生命上限 = 0;
            if (生命level!=0){
                int 生命attr = main.config.getInt("jineng.生命."+生命level+".attr");

                if (大师level!=0){
                    int 大师attr = main.config.getInt("jineng.大师."+大师level+".attr");
                    double 大师percent = (double) 大师attr/100;
                    生命attr = 生命attr+(int) (生命attr*大师percent);
                }
                生命上限 = 生命上限+生命attr;
            }
            if (高级生命level!=0){
                int 高级生命attr = main.config.getInt("jineng.高级生命."+高级生命level+".attr");

                if (大师level!=0){
                    int 大师attr = main.config.getInt("jineng.大师."+大师level+".attr");
                    double 大师percent = (double) 大师attr/100;
                    高级生命attr = 高级生命attr+(int) (高级生命attr*大师percent);
                    生命上限 =生命上限+高级生命attr;
                }
            }
            List<String> Attribute = new ArrayList<String>();
            Attribute.add("物理伤害: "+物理伤害);
            Attribute.add("物理防御: "+物理防御);
            Attribute.add("生命上限： "+生命上限);
           AttributeData attributedata = AttributeAPI.getAttrData(p);
            AttributeAPI.addSourceAttribute(attributedata,"shenfu-jineng",Attribute,false);
            Double zhanli = AttributeAPI.getAttributeSource(Attribute,false).getCombatPower();
            //todo 将战力放到main类的技能战力统计map里
            main.PlayerJiNengZhanLi.put(p,zhanli.intValue());
        }
}
